package com.egoo.ticket.server.controller;

import com.egoo.ticket.server.pojo.entity.CustomFieldDataSource;
import com.egoo.ticket.server.service.CustomFieldDataSourceService;
import com.egoo.ticket.server.utils.common.CreateCodeUtil;
import com.egoo.ticket.server.utils.common.DbResponse;
import com.egoo.ticket.server.utils.common.RedisUtil;
import com.egoo.ticket.server.utils.common.ResponseConstant;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author：victor_tang
 * @Date ：2020/3/31
 * @Description：自定义字段特定数据源控制层
 */
@RestController
@RequestMapping(value = "/v1/customFieldDataSource", produces = "application" +
		"/json")
@Api(value = "自定义字段数据源管理",tags = "自定义字段数据源",
		description = "自定义字段数据源管理")
public class CustomFieldDataSourceController {

	@Autowired
	private CustomFieldDataSourceService customFieldDataSourceService;
	@Autowired
	private RedisUtil redisUtil;
	@Autowired
	private CreateCodeUtil createCodeUtil;

	@ApiOperation(value = "根据id获取自定义字段数据源内容", notes = "根据id获取自定义字段数据源内容")
	@RequestMapping(method = RequestMethod.GET, value="/getDataContentById")
	public DbResponse getDataContentById(@ApiParam(value = "数据源id", required = true)
											 @RequestParam(name = "id") String id){
		if (StringUtils.isEmpty(id)) {
			return new DbResponse(ResponseConstant.RES_FAIL_CODE,
					"自定义字段数据源id不能为空！");
		}
		CustomFieldDataSource dataSource = customFieldDataSourceService.getDataSourceById(id);
		if (dataSource==null ||dataSource.getDataContent()==null) {
			return new DbResponse(ResponseConstant.RES_FAIL_CODE,
					"自定义字段数据源信息未找到！");
		}
		return new DbResponse(ResponseConstant.RES_SUCCESS_CODE,
				ResponseConstant.SELECT_SUCCESS_MSG,dataSource.getDataContent());
	}
}
